﻿

//function prepareGetInplaceAjax() {
//	// call href, or function in href , also use to load the form in place of a read-only paragraph

//	// obsolete // im going to still use it in mockups, replace all calls of data-behavior=GetInPlaceAjax to data-behavior=InPlaceAjax
//	this.click(function (e) {
//		
//		if (e.isDefaultPrevented()) return false;

//		// call href in ajax, loading... then call onloadfn function
//		// DEVS: if u need any more customization write a new function alltogether
//		$t = $(this).addClass("loadings inplaceloading"); //TODO: ayyash, add classes to css
//		$.get($t.attr('href'), function (data) {
//			// remove loading
//			$t.removeClass("loadings inplaceloading");
//			// check onloadfn and fire
//			var onfinish = $t.attr("data-onfinish");

//			if (onfinish) {
//				var onfinishFn = eval(onfinish);
//				if (typeof onfinishFn === 'function') {
//					onfinishFn.call($t, data);
//				}
//			} else {
//				// replace content
//				var $tparent = $t.parent();
//				$t.replaceWith(data);
//				rewireload($tparent);

//			}

//		});
//		e.preventDefault();
//	});

//}
//function prepareInplaceAjax() {
//	// call href, or function in href , also use to load the form in place of a read-only paragraph

//	// TODO: how to make the href a webservice call instead of url


//	this.click(function (e) {

//		if (e.isDefaultPrevented()) return false;

//		// call href in ajax, loading... then call onloadfn function
//		// DEVS: if u need any more customization write a new function alltogether
//		$t = $(this).addClass("loadings inplaceloading"); //TODO: ayyash, add classes to css
//		$.ajax($t.attr('href'), function (data) {
//			// remove loading
//			$t.removeClass("loadings inplaceloading");
//			// check onloadfn and fire
//			var onfinish = $t.attr("data-onfinish");

//			if (onfinish) {
//				var onfinishFn = eval(onfinish);
//				if (typeof onfinishFn === 'function') {
//					onfinishFn.call($t, data);
//				}
//			} else {
//				// replace content
//				var $tparent = $t.parent();
//				$t.replaceWith(data);
//				rewireload($tparent);

//			}

//		});
//		e.preventDefault();
//	});

//}

function prepareGetInplaceAjax() {
	this.click(function (e) {
		if (e.isDefaultPrevented()) {
			return false;
		} $t = $(this).addClass("loadings inplaceloading"); $.get($t.attr("href"), function (data) {
			$t.removeClass("loadings inplaceloading");
			var onfinish = $t.attr("data-onfinish"); if (onfinish) {
				var onfinishFn = eval(onfinish);
				if (typeof onfinishFn === "function") { onfinishFn.call($t, data); } 
			} else {
				var $tparent = $t.parent();
				$t.replaceWith(data); rewireload($tparent);
			} 
		}); e.preventDefault();
	});
} function prepareInplaceAjax() {
	this.click(function (e) {
		if (e.isDefaultPrevented()) {
			return false;
		} $t = $(this).addClass("loadings inplaceloading"); $.ajax({ url: $t.attr("href"), type: "POST", data: $t.attr("data-params"), dataType: "json", contentType: "application/json; charset=utf-8", success: function (data) {
			$t.removeClass("loadings inplaceloading");
			var onfinish = $t.attr("data-onfinish"); if (onfinish) {
				var onfinishFn = eval(onfinish);
				if (typeof onfinishFn === "function") { onfinishFn.call($t, data); } 
			} else {
				var $tparent = $t.parent();
				$t.replaceWith(data); rewireload($tparent);
			} 
		}, error: function (data) {
			console.log(data.responseText);
		} 
		}); e.preventDefault();
	});
}